//
//  HJJPlayerListView.m
//  Pianke
//
//  Created by 黄俊杰 on 15/12/29.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "HJJPlayerListView.h"
#import "HJJPlayerListCell.h"
#import "HJJRadioRootModel.h"

@implementation HJJPlayerListView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

-(void)createView{

    self.listArray = [NSMutableArray array];
    
    //tableView
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375 * EACH_WIDTH, 437 * EACH_HEIGHT) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.separatorColor = BLUECOLOR;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.myTableView];
    [self.myTableView registerClass:[HJJPlayerListCell class] forCellReuseIdentifier:@"HJJPlayerListCell"];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 45 * EACH_HEIGHT;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.listArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellId = @"HJJPlayerListCell";
    HJJPlayerListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    cell.backgroundColor = [UIColor clearColor];
    if (self.indexRow == indexPath.row) {
        cell.playImage.image = [UIImage imageNamed:@"playing.png"];
    }else{
        cell.playImage.image = nil;
    }
    HJJRadioRootModel *model = [self.listArray objectAtIndex:indexPath.row];
    [cell sendModel:model];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:1];
    if (indexPath.row != self.indexRow) {
        [self.playerListViewDele backIndexPath:indexPath];
    }else{
    
    }
    
}

-(void)reciveData:(NSMutableArray *)array indexRow:(NSInteger)indexRow{

    self.listArray = [NSMutableArray arrayWithArray:array];
    self.indexRow = indexRow;
    [self.myTableView reloadData];
}
@end
